package cn.alibab.sys.controller;

import cn.alibab.common.model.PageBean;
import cn.alibab.common.model.R;
import cn.alibab.sys.model.SysUser;
import cn.alibab.sys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

/**
 * @author shiyk
 * @create 2020-07-01 9:10
 */
@RestController
@RequestMapping("sys/user")
@Api(tags = "用户管理")
public class UserController {
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    //api 配合 swagger 使用  是用来做前后台分离的项目方便给前台做测试接口
    @ApiOperation("得到所有用户")
    @GetMapping
    @RequiresPermissions("sys:user:get")
    public R gteUser(String username, PageBean pageBean) {
        return userService.getUser(username, pageBean);

    }

    @PutMapping("/{id}/{isvalid}")
    public R updateUserState(@PathVariable("id") Long id, @PathVariable("isvalid") Boolean isvalid) {
        return userService.updateUserState(id, isvalid);

    }

    @DeleteMapping("/{userId}")
    public R delUserById(@PathVariable("userId") Long userId) {
        return userService.delUserById(userId);
    }

    @PostMapping
    public R addUser(@RequestBody SysUser sysUser) {
        return userService.addUser(sysUser);
    }

    @PutMapping
    public R editUser(@RequestBody SysUser sysUser) {
        return userService.editUser(sysUser);
    }

    @PostMapping("login")
    public R longin(String username, String password) {
        return userService.longin(username, password);
    }
    @GetMapping("info")
    public R info(){
        return userService.info();
    }
}
